// page/shangpinxiangqin/shangpinxiangpin.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        dianzanshu:0,
        baseURL:wx.baseURL,
        xiangqing:{},
        skus:{},
        first_id:0,
        flag:0,
        gmshu:1,
        top:740,


        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 4000,
        duration: 500 ,
    },


    tcguige(){
        let flag = this.data.flag
        flag++
        if(flag==2){
            flag=0
        }

        this.setData({
            flag,
            top:0
        })
    },


    beijin(){
        this.setData({
            flag:0,
            top:740
        })
    },
    guanbi(){
        this.setData({
            flag:0,
            top:740
        })
    },

    xzguige(e){
        let index =  e.currentTarget.dataset.index 
        console.log(index)
        this.setData({
            first_id:index
        })
    },

    jian(){
        let shuliang = this.data.gmshu
        if(shuliang>0){
            shuliang --
            this.setData({
                gmshu:shuliang
            })
        }
    },
    jia(){
        let shuliang = this.data.gmshu
            shuliang ++
            this.setData({
                gmshu:shuliang
            })
    },

    dianzan(){
        let zan = this.data.dianzanshu
        zan++
        this.setData({
            dianzanshu:zan
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.$https.get('/product',{productId:options.productId}).then((res)=>{   
            console.log(res)  
            res.imgs = res.imgs.split(',')
            
            this.setData({
                skus:res.skus,
                xiangqing:res
            }) 
            wx.setNavigationBarTitle({
              title: res.name,
            })
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function (e) {
        console.log(e)
        return{
            title:this.data.xiangqing.name,
            path:'/pages/index/index?userId=1',
            imageUrl:''
        }
    }
})